package com.intelligence.pda.ui.scanlibrary.adapter;

import android.content.Context;
import android.content.Intent;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.intelligence.pda.R;
import com.intelligence.pda.ui.scanlibrary.DetailsActivity;
import com.intelligence.pda.ui.scanlibrary.model.OutstockListModel;
import com.intelligence.pda.utils.AppConstants;

import java.util.ArrayList;

/**
 * Created by Administrator
 * on 2017/10/18.
 */

public class ScanlibraryAdapter extends RecyclerView.Adapter<ScanlibraryAdapter.ViewHolder> {
    public ArrayList<OutstockListModel.DataBean> datas = null;
    public Context mContext;

    public ScanlibraryAdapter(Context context, ArrayList<OutstockListModel.DataBean> datas) {
        this.datas = datas;
        this.mContext = context;
    }

    //创建新View，被LayoutManager所调用
    @Override
    public ViewHolder onCreateViewHolder(ViewGroup viewGroup, int viewType) {
        View view = LayoutInflater.from(viewGroup.getContext()).inflate(R.layout.item_scan_library, viewGroup, false);
        return new ViewHolder(view);
    }

    //将数据与界面进行绑定的操作
    @Override
    public void onBindViewHolder(ViewHolder viewHolder, final int position) {
        viewHolder.tv_takeTime.setText(datas.get(position).getTakeTime());
        viewHolder.tv_waybillNo.setText("运单号:" + datas.get(position).getWaybillNo());
        viewHolder.tv_orderNum.setText(datas.get(position).getOrderNum() + "笔");
        viewHolder.tv_scan.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(mContext, DetailsActivity.class);
                intent.putExtra(AppConstants.DETAILS,datas.get(position).getOrderNos());
                mContext.startActivity(intent);
            }
        });

    }

    //获取数据的数量
    @Override
    public int getItemCount() {
        return datas.size();
    }

    //自定义的ViewHolder，持有每个Item的的所有界面元素
    public static class ViewHolder extends RecyclerView.ViewHolder {
        public TextView tv_takeTime;
        public TextView tv_waybillNo;
        public TextView tv_orderNum;
        public TextView tv_scan;

        public ViewHolder(View view) {
            super(view);
            tv_takeTime = (TextView) view.findViewById(R.id.tv_takeTime);
            tv_waybillNo = (TextView) view.findViewById(R.id.tv_waybillNo);
            tv_orderNum = (TextView) view.findViewById(R.id.tv_orderNum);
            tv_scan = (TextView) view.findViewById(R.id.tv_scan);
        }
    }
}